package com.linln.admin.upload;

import com.linln.common.utils.PathMappingUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : pengliang
 * @version V1.0
 * @Project: timo
 * @Package com.linln.admin.upload
 * @Descriptio /**
 * @Project: timo
 * @Package com.linln.admin.upload
 * @Description: TODO
 * @date Date : 2020年12月15日 15:24
 */
@RestController
@RequestMapping("editorUploadImg")
public class EditorUpload {

    @Value("${server.ip}")
    String ip;

    @PostMapping
    public Map<String, Object> upload(StandardMultipartHttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        Map<String, MultipartFile> fileMap = request.getFileMap();
        List<String> list = new ArrayList<>();
        fileMap.values().forEach(item -> {
            String s = PathMappingUtil.saveImg(PathMappingUtil.EDITORIMGPATH, PathMappingUtil.EDITORIMGMAPPING, item);
            s = ip + s;
            list.add(s);
        });
        map.put("data", list);
        map.put("errno", 0);
        return map;
    }
}
